﻿using Quartz.Spi;
using Quartz;

namespace MyWeb.ScheduledTasks
{
    public class DefaltIJobFactory : IJobFactory
    {
        private static IServiceScopeFactory? _serviceProvider;
        public DefaltIJobFactory(IServiceScopeFactory serviceScopeFactory)
        {

            _serviceProvider = serviceScopeFactory;
        }

        public IJob? NewJob(TriggerFiredBundle bundle, IScheduler scheduler)
        {
            try
            {
                var sevice = _serviceProvider.CreateScope();
                return sevice.ServiceProvider.GetService(bundle.JobDetail.JobType) as IJob;
            }
            catch (Exception ex)
            {

                throw;
            }
            //return  
        }

        public void ReturnJob(IJob job)
        {
            (job as IDisposable)?.Dispose();
        }
    }
}
